package com.anolesoft.amljmes.foreknow.mapper;

import com.anolesoft.amljmes.foreknow.bo.MesBzzPtdmx;
import com.anolesoft.amljmes.foreknow.bo.MesBzzQfbld;
import com.anolesoft.amljmes.foreknow.bo.MesBzzQfbldmx;
import com.anolesoft.amljmes.foreknow.dto.MesBzzQfbldDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MesBzzQfbldMapper {
    /**
     * 插入铅封保留单
     * @param qfbld
     * @return
     */
    int insertData(MesBzzQfbld qfbld);

    /**
     * 插入铅封保留单明细
     * @param qfbldmx
     * @return
     */
    int insertMx(MesBzzQfbldmx qfbldmx);

    /**
     * 修改状态为1
     * @return
     */
    int updateState(MesBzzPtdmx mesBzzPtdmx);

    /**
     * 修改状态为2
     * @return
     */
    int updateStates(MesBzzPtdmx mesBzzPtdmx);

    /**
     * 查询保留单匹配条数--------------------------1(改好)
     * @param objuid
     * @return
     */
    @Select("SELECT COUNT(*) FROM MES_BZZ_QFBLD WHERE STATE = 0 AND MATCHING_DOC_PK = #{objuid}")
    int selectAll(String objuid);

    /**
     * 查询明细匹配条数----------------------------2(无厂代号)
     * @param objuid
     * @return
     */
    @Select("SELECT COUNT(*) FROM MES_BZZ_QFBLDMX WHERE STATE = 0 AND PTDMX_UID = #{objuid}")
    int selectMx(String objuid);

    /**
     * 修改用户输入的三条数据
     * @param qfbldmx
     * @return
     */
    @Update("UPDATE MES_BZZ_QFBLDMX  SET JINZHAN = #{jinzhan},PROMISE_DATE = #{promiseDate},BLSL = #{blsl} WHERE PTDMX_UID = #{ptdmxUid} and state = 0")
    int updateThree(MesBzzQfbldmx qfbldmx);

    /**
     * 查询铅封保留单----------------------------3(改好)
     * @param qfbldDto
     * @return
     */
    List<MesBzzQfbld> query (MesBzzQfbldDto qfbldDto);

    /**
     * 查询铅封保留单明细------------------------4(没有厂代号)
     * @param objuid
     * @return
     */
    @Select("SELECT * FROM MES_BZZ_QFBLDMX WHERE STATE = 0 AND QFBLD_UID = #{objuid}")
    List<MesBzzQfbldmx> queryMx(String objuid);

    /**
     * 修改铅封保留单明细状态
     */
    @Update("UPDATE MES_BZZ_QFBLDMX SET STATE = 1 WHERE OBJUID = #{objuid}")
    int updatemxState(String objuid);
    /**
     * 修改配套单明细保留数量
     */
    @Update("UPDATE MES_BZZ_PTDMX SET BAOLIUNUM = 0 WHERE OBJUID = #{ptdmxUid}")
    int updateNum(String ptdmxUid);
    /**
     * 查询该保留单下是否还存在明细(在铅封保留单明细中用保留单主键查询)
     */
    @Select("SELECT COUNT(*) FROM MES_BZZ_QFBLDMX WHERE STATE = 0 AND QFBLD_UID = #{qfbldUid}")
    int selectNum(String qfbldUid);
    /**
     * 修改铅封保留单状态(如果没有明细作废)
     */
    @Update("UPDATE MES_BZZ_QFBLD SET STATE = 1 WHERE OBJUID = #{qfbldUid}")
    int updatebldstate(String qfbldUid);
    /**
     * 修改配套单明细保留数量
     */
    @Update("UPDATE MES_BZZ_PTDMX SET shifoubaoliu = 0 WHERE OBJUID = #{ptdmxUid}")
    int updateptdstate(String ptdmxUid);
    /**
     * 查询铅封保留单主键
     */
    @Select("SELECT OBJUID FROM MES_BZZ_QFBLD WHERE MATCHING_DOC_PK = #{matchingDocPk} AND STATE = 0")
    String selectObjuid(String matchingDocPk);
    /**
     * 查询多条明细----------------------------5
     */
    List<MesBzzQfbldmx> querydmingxi(String id);
    /**
     * 改变铅封保留单明细保留单数量
     */
    @Update("UPDATE MES_BZZ_QFBLDMX SET BLSL = 0, promise_date = null, jinzhan = null WHERE OBJUID =  #{objuid}")
    int updateqfbldnum(String objuid);

    /**
     * 获取序列的流水号
     * @return
     */
    @Select(" select jjmes_qfbld.nextval as con from dual ")
    int liuShuiHao();
}
